package com.stockz.equity.charting.view.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.JMenuItem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import com.stockz.equity.charting.view.StockChartPanelState;
import com.stockz.equity.charting.view.StockChartView;
import com.stockz.equity.pattern.Child;

@Component
public class ResetChartMenuItem extends JMenuItem implements Child,Ordered {
	private static final long serialVersionUID = 646307461526391359L;

	@SuppressWarnings("rawtypes")
	private List<Class> parentList = new ArrayList<Class>(1);
	
	@Autowired
	private StockChartView view;
	
	public ResetChartMenuItem(){
		super("Reset Chart");

		parentList.add(StockChartRightClickPopupMenu.class);
		addActionListener(new ActionListener(){

			@Override
			public void actionPerformed(ActionEvent e) {
				view.getSelectedStockChart().getStockChartPanel().getStockChartPanelState();
				StockChartPanelState state =view.getSelectedStockChart().getStockChartPanel().getStockChartPanelState();
				state.getBarList().clear();
				state.getBarList().addAll(state.getBackupBarList());
			}
		});
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public Collection<Class> getParents() {
		return parentList;
	}
	
	@Override
	public int getOrder() {
		return 0;
	}

}
